dojo.provide("msos.on_screen_kb");
dojo.require("msos.characters");
dojo.require("msos.common");
dojo.require("msos.input_events");
dojo.require("msos.input_select");
dojo.require("msos.selection");
dojo.require("dojo.dnd.Moveable");
dojo.require("dojo.i18n");
msos.on_screen_kb.create_tool=function(_1,_2,_3,_4,_5){
dojo.requireLocalization("msos","keyboard",djConfig.locale);
this.i18n=dojo.i18n.getLocalization("msos","keyboard",djConfig.locale);
this.container=_1;
this.header=_2;
this.close=_3;
this.display=_4;
this.created=false;
this.i18n_idx=0;
this.tool_target=null;
this.tool_iframe=null;
this.suppressed_elements=new Array();
this._vars={debug:"Keyboard Element Build:\n\n",flag_caps:false,flag_shift:false,flag_alt:false,start_lang:djConfig.locale,char_keys:new Array(),ctrl_keys:new Array(),not_avail:new Array(2),key_position:{top:1,left:1},adj_left:0,adj_top:0,image_url:djConfig.msos_folder+"/images/",ie_element_suppression:["select","object","applet"],fc:"#000",bg:"#FFF",bc:"#777",ibc:"#CCC",lsc:"#FF99CC",lic:"#DDD"};
new dojo.dnd.Moveable(_1);
for(var j=0;j<_5.length;j++){
if(/textarea|text|password/i.test(_5[j].type)){
var _7=_5[j].value;
_5[j].value=dojo.trim(_7);
}
}
var _8=this;
this.set_input_focus_end=function(_9){
var _a=new msos.input_select.text_ins_del(_9);
_a.input_init_focus();
_a.input_set_cursor();
_8.tool_target=_9;
msos.common.debug_write(_a.debug);
};
this.keyb_button_onmouseup=function(){
if(!_8.created){
msos.input_events.set_event(_8,_5);
msos.common.set_popup_position(_8.container,_5[0],_8._vars);
generate_keyboard(_8);
_8.display_kb_window();
_8.created=true;
return true;
}
if((_8.container.style.visibility=="")||(_8.container.style.visibility=="visible")){
_8.hide_kb_window();
}else{
_8.display_kb_window();
}
return true;
};
this.select_lang_onclick=function(_b){
_b.preventDefault();
_b.stopPropagation();
var _c=_b.target;
if(_c.key_is_active){
++_8.i18n_idx;
if(_8.i18n_idx>(msos.characters.available.length-1)){
_8.i18n_idx=0;
}
refresh_layout(_8);
}
msos.common.event_debug(_b,"\nLanguage index -> "+_8.i18n_idx);
};
this.process_key_onclick=function(_d){
_d.preventDefault();
_d.stopPropagation();
var _e=_d.target;
var _f=_8._vars;
var _10="";
var val=_e.subst?_e.subst:_e.innerHTML;
if(_e.key_is_active){
if((val=="Caps")||(val=="Shift")||(val=="Alt")){
var _12="flag_"+val.toLowerCase();
_f[_12]=_f[_12]?false:true;
val="";
}else{
if(_e.dead){
if(_e.dead==_f.not_avail[1]){
_f.not_avail[0]=null;
_f.not_avail[1]=null;
}else{
_f.not_avail[0]=val;
_f.not_avail[1]=_e.dead;
}
val="";
}else{
if(_f.not_avail[1]){
_f.not_avail[0]=null;
_f.not_avail[1]=null;
}
_f.flag_alt=false;
_f.flag_shift=false;
}
}
refresh_layout(_8);
if(val&&_8.tool_target){
if(/textarea|text|password/i.test(_8.tool_target.type)){
var _13=new msos.input_select.text_ins_del(_8.tool_target);
_13.input_init_focus();
switch(val){
case "BkSp":
_13.input_del_character(false);
break;
case "Del":
_13.input_del_character(true);
break;
case "Tab":
_13.input_ins_character("\t");
break;
case "LF":
_13.input_ins_character("\n");
break;
case "BR":
_13.input_ins_character("<br />");
break;
case "SP":
_13.input_ins_character("&#160;");
break;
case "Space":
_13.input_ins_character(" ");
break;
case "&lt;":
_13.input_ins_character("<");
break;
case "&gt;":
_13.input_ins_character(">");
break;
case "&amp;":
_13.input_ins_character("&");
break;
case "&quot;":
_13.input_ins_character("\"");
break;
case " ":
break;
case "&#160;":
break;
default:
_13.input_ins_character(val);
}
_10=_13.debug;
}else{
if(_8.tool_iframe){
var ifr=_8.tool_iframe;
var win=ifr.contentWindow;
var doc=win.document;
switch(val){
case "BkSp":
msos.input_select.set_bksp_del_select(win,doc,ifr,true);
break;
case "Del":
msos.input_select.set_bksp_del_select(win,doc,ifr,false);
break;
case "Tab":
msos.input_select.edit_insert_html(win,doc,ifr,"\t");
break;
case "LF":
msos.input_select.edit_insert_html(win,doc,ifr,"<br />");
break;
case "BR":
msos.input_select.edit_insert_html(win,doc,ifr,"<br />");
break;
case "SP":
msos.input_select.edit_insert_html(win,doc,ifr,"&#160;");
break;
case "Space":
var _17=" ";
if(dojo.isIE){
_17="&#160;";
}
msos.input_select.edit_insert_html(win,doc,ifr,_17);
break;
case " ":
break;
case "&#160;":
break;
default:
msos.input_select.edit_insert_html(win,doc,ifr,val);
}
_10="\nIframe detected";
}
}
}else{
console.debug("process_key_onclick -> Failed: "+(val?"missing tool target!":"missing value!"));
}
}
if(djConfig.msos_debug){
var _18=_e.key_is_active?"true":"false";
var _19=_e.dead?_e.dead:"false";
var _1a=_e.subst?_e.subst:"na";
var _1b=_e.innerHTML?_e.innerHTML:"na";
_10="\nProcess key:"+"\nValue  -> "+val+"\nSubst  -> "+_1a+"\nInner  -> "+_1b+"\nActive -> "+_18+"\nDead   -> "+_19+_10;
msos.common.event_debug(_d,_10);
}
};
};
msos.on_screen_kb.create_tool.prototype.hide_kb_window=function(){
this.container.style.visibility="hidden";
this.restore_ie_objects();
};
msos.on_screen_kb.create_tool.prototype.display_kb_window=function(){
this.suppress_ie_objects();
this.container.style.visibility="visible";
};
msos.on_screen_kb.create_tool.prototype.suppress_ie_objects=function(){
msos.common.set_suppress_ie_objects(this.container,this._vars.ie_element_suppression,this.suppressed_elements);
for(i=0;i<this.suppressed_elements.length;i++){
this.suppressed_elements[i].style.visibility="hidden";
}
};
msos.on_screen_kb.create_tool.prototype.restore_ie_objects=function(){
for(i=0;i<this.suppressed_elements.length;i++){
this.suppressed_elements[i].style.visibility="";
}
this.suppressed_elements=[];
};
function generate_keyboard(_1c){
var _1d=_1c.display;
var _1e=_1c._vars;
var e="&#160;";
var i;
var _21=function(_22,_23,_24){
var _25=String(_1c._vars.key_position.top)+"px";
var _26=String(_1c._vars.key_position.left)+"px";
if(djConfig.debugAtAllCost){
_1c._vars.debug+="Top  -> "+_25+", Left  -> "+_26;
_1c._vars.debug+="\nKey -> "+_22+", Class -> "+_24+"\n";
}
var _27=document.createElement("div");
_27.className=_24;
_27.innerHTML=_22;
_27.title=_23;
_27.style.top=_25;
_27.style.left=_26;
dojo.connect(_27,"onmousedown",null,function(){
_27.style.borderStyle="inset";
});
dojo.connect(_27,"onmouseup",null,function(){
_27.style.borderStyle="outset";
});
_1c.display.appendChild(_27);
return _27;
};
for(var j=0;j<msos.characters.available.length;j++){
if(_1e.start_lang==msos.characters.available[j][2]){
_1c.i18n_idx=j;
}
}
msos.selection.disableSelection(_1c.container);
msos.selection.disableSelection(_1c.header);
msos.selection.disableSelection(_1c.close);
msos.selection.disableSelection(_1c.display);
var _29={img_name:"close_button.gif",img_url:_1e.image_url,img_title:_1c.i18n.close_title,img_alt:_1c.i18n.close_alt,img_size:"img_cls",img_but_id:"img_close",button_mouseup:_1c.keyb_button_onmouseup};
var _2a=new msos.common.generate_img_button(_1c.close);
for(var val in _29){
_2a[val]=_29[val];
}
_2a.img_button_append();
_1c.header.innerHTML="<span title=\""+_1c.i18n.kb_position+"\" class=\"bold_text\">.. :: :: :: ..</span>";
for(i=0;i<13;i++){
var _2c;
_2c=_21(i,"","std_kb_cell");
_1e.key_position.left+=_2c.offsetWidth+1;
_1e.char_keys[i]=_2c;
}
_1e.ctrl_keys["backsp"]=_21("BkSp",_1c.i18n.backspace,"bk_space_cell");
_1e.key_position.top=_1e.char_keys[0].offsetHeight+2;
_1e.key_position.left=1;
_1e.ctrl_keys["tab"]=_21("Tab",_1c.i18n.tab+" - \\t","tab_cell");
_1e.key_position.left+=_1e.ctrl_keys["tab"].offsetWidth+1;
for(i;i<26;i++){
var _2d;
_2d=_21(i,"","std_kb_cell");
_1e.key_position.left+=_2d.offsetWidth+1;
_1e.char_keys[i]=_2d;
}
_1e.ctrl_keys["et"]=_21(e,_1c.i18n.linefeed+" - \\n","lf_top_cell");
_1e.ctrl_keys["et"].subst="LF";
_1e.key_position.top=_1e.char_keys[0].offsetHeight+_1e.ctrl_keys["tab"].offsetHeight+3;
_1e.key_position.left=1;
_1e.ctrl_keys["caps"]=_21("Caps",_1c.i18n.caps_lock,"caps_cell");
_1e.key_position.left+=_1e.ctrl_keys["caps"].offsetWidth+1;
for(i;i<38;i++){
var _2e=_21(i,"","std_kb_cell");
_1e.key_position.left+=_2e.offsetWidth+1;
_1e.char_keys[i]=_2e;
}
_1e.ctrl_keys["e"]=_21("LF",_1c.i18n.linefeed+" - \\n","enter_cell");
_1e.key_position.top=_1e.char_keys[0].offsetHeight+_1e.ctrl_keys["tab"].offsetHeight+_1e.ctrl_keys["caps"].offsetHeight+4;
_1e.key_position.left=1;
_1e.ctrl_keys["sh"]=_21("Shift",_1c.i18n.shift,"shift_cell");
_1e.key_position.left+=_1e.ctrl_keys["sh"].offsetWidth+1;
for(i;i<48;i++){
var _2f=_21(i,"","std_kb_cell");
_1e.key_position.left+=_2f.offsetWidth+1;
_1e.char_keys[i]=_2f;
}
_1e.ctrl_keys["sr"]=_21("Shift",_1c.i18n.shift,"shift_cell");
_1e.key_position.top=_1e.char_keys[0].offsetHeight+_1e.ctrl_keys["tab"].offsetHeight+_1e.ctrl_keys["caps"].offsetHeight+_1e.ctrl_keys["sh"].offsetHeight+5;
_1e.key_position.left=1;
_1e.ctrl_keys["lang"]=_21(e,"","bottom_cell");
_1e.key_position.left+=_1e.ctrl_keys["lang"].offsetWidth+1;
_1e.ctrl_keys["sp"]=_21("SP",_1c.i18n.html+" &#160;","bottom_cell");
_1e.key_position.left+=_1e.ctrl_keys["sp"].offsetWidth+1;
_1e.ctrl_keys["res_2"]=_21(e,"","bottom_cell");
_1e.key_position.left+=_1e.ctrl_keys["res_2"].offsetWidth+1;
_1e.ctrl_keys["space"]=_21("Space",_1c.i18n.space,"space_cell");
_1e.key_position.left+=_1e.ctrl_keys["space"].offsetWidth+1;
_1e.ctrl_keys["del"]=_21("Del",_1c.i18n.del_key,"bottom_cell");
_1e.key_position.left+=_1e.ctrl_keys["del"].offsetWidth+1;
_1e.ctrl_keys["altgr"]=_21("Alt",_1c.i18n.alt,"bottom_cell");
_1e.key_position.left+=_1e.ctrl_keys["altgr"].offsetWidth+1;
_1e.ctrl_keys["br"]=_21("BR",_1c.i18n.html+" <br />","bottom_cell");
for(var j=0;j<_1e.char_keys.length;j++){
var key=_1e.char_keys[j];
key.unselectable="on";
dojo.connect(key,"onclick",null,_1c.process_key_onclick);
}
for(var k in _1e.ctrl_keys){
var key=_1e.ctrl_keys[k];
key.unselectable="on";
if(k=="lang"){
dojo.connect(key,"onclick",null,_1c.select_lang_onclick);
}else{
dojo.connect(key,"onclick",null,_1c.process_key_onclick);
}
}
refresh_layout(_1c);
if(djConfig.debugAtAllCost){
alert(_1e.debug);
}
};
function refresh_layout(vkb){
var _33=function(key,_35,_36,_37,_38,_39){
if(!key){
return false;
}
if(key.style){
if(_36){
key.style.color=_36;
}
if(_37){
key.style.borderColor=_37;
}
if(_38){
key.style.backgroundColor=_38;
}
if(_39){
key.style.fontWeight=_39;
}
}
key.key_is_active=_35;
return true;
};
var _3a=msos.characters.available[vkb.i18n_idx][0].toLowerCase();
var _3b=vkb._vars.flag_alt?(vkb._vars.flag_shift?"alt_gr_shift":"alt_gr"):(vkb._vars.flag_shift?"shift":(vkb._vars.flag_caps?"caps":"normal"));
var _3c=vkb._vars.char_keys.length;
var _3d=_3a+"_caps";
var _3e=_3a+"_shift";
var _3f=_3a+"_alt_gr";
var _40=_3a+"_alt_gr_shift";
var _41=vkb._vars.ctrl_keys["caps"],_42=vkb._vars.ctrl_keys["sh"],_43=vkb._vars.ctrl_keys["sr"];
var _44=vkb._vars.ctrl_keys["altgr"],_45=vkb._vars.ctrl_keys["space"],_46=vkb._vars.ctrl_keys["lang"];
var _47=vkb._vars.ctrl_keys["et"],_48=vkb._vars.ctrl_keys["e"];
var _49=vkb._vars.ctrl_keys["sp"],_4a=vkb._vars.ctrl_keys["br"];
if(msos.characters.groups[_3e]&&(msos.characters.groups[_3e].length==_3c)){
_33(_42,true,vkb._vars.fc,vkb._vars.bc,vkb._vars.flag_shift?vkb._vars.lic:vkb._vars.bg);
_33(_43,true,vkb._vars.fc,vkb._vars.bc,vkb._vars.flag_shift?vkb._vars.lic:vkb._vars.bg);
}else{
_33(_42,false,vkb._vars.ibc,vkb._vars.ibc,vkb._vars.bg);
_33(_43,false,vkb._vars.ibc,vkb._vars.ibc,vkb._vars.bg);
if(_3b=="shift"){
_3b="normal";
vkb._vars.flag_shift=false;
}
}
if(msos.characters.groups[_3f]&&(msos.characters.groups[_3f].length==_3c)){
_33(_44,true,vkb._vars.fc,vkb._vars.bc,vkb._vars.flag_alt?vkb._vars.lic:vkb._vars.bg);
if(vkb._vars.flag_alt){
if(msos.characters.groups[_40]&&(msos.characters.groups[_40].length==_3c)){
_33(_42,true,vkb._vars.fc,vkb._vars.bc,"");
_33(_43,true,vkb._vars.fc,vkb._vars.bc,"");
}else{
_33(_42,false,vkb._vars.ibc,vkb._vars.ibc,vkb._vars.bg);
_33(_43,false,vkb._vars.ibc,vkb._vars.ibc,vkb._vars.bg);
_3b="alt_gr";
vkb._vars.flag_shift=false;
}
}
}else{
_33(_44,false,vkb._vars.ibc,vkb._vars.ibc,vkb._vars.bg);
if(_3b=="alt_gr"){
_3b="normal";
vkb._vars.flag_alt=false;
}else{
if(_3b=="alt_gr_shift"){
_3b="normal";
vkb._vars.flag_alt=false,vkb._vars.flag_shift=false;
_42.style.backgroundColor=vkb._vars.bg,_43.style.backgroundColor=vkb._vars.bg;
}
}
}
if(msos.characters.groups[_3d]&&(msos.characters.groups[_3d].length==_3c)&&!vkb._vars.flag_alt){
_33(_41,true,vkb._vars.fc,vkb._vars.bc,vkb._vars.flag_caps?vkb._vars.lic:vkb._vars.bg);
}else{
_33(_41,false,vkb._vars.ibc,vkb._vars.ibc,vkb._vars.bg);
vkb._vars.flag_caps=false;
if(_3b=="caps"){
_3b="normal";
}
}
for(var i=0;i<_3c;i++){
var key=vkb._vars.char_keys[i];
var _4d="";
if(vkb._vars.flag_shift&&vkb._vars.flag_caps){
var _4e=msos.characters.groups[_3a+"_normal"][i];
var _4f=msos.characters.groups[_3a+"_caps"][i];
var _50=msos.characters.groups[_3a+"_shift"][i];
if((_4f==_50)&&(_4e!=_4f)){
_4d=_4e||"";
}
}else{
_4d=msos.characters.groups[_3a+"_"+_3b][i]||"";
}
if(String(typeof (_4d)).toLowerCase()=="object"){
msos.common.xml_innerhtml(key,_4d[0]);
key.dead=_4d[1];
_33(key,true,"#F00",vkb._vars.bc,(vkb._vars.not_avail[0]==_4d[0]?vkb._vars.lic:vkb._vars.bg));
}else{
key.dead=null;
var _51=false;
var _52=vkb._vars.not_avail[1]||null;
if(_4d!=""){
if(_52){
var j;
_52=_52.toLowerCase();
var _54=msos.characters.diacritic[_52]||null;
for(j=0;j<_54.length;j++){
if(_54&&(_54[j][0]==_4d)){
_4d=_54[j][1];
break;
}
}
if(j==_54.length){
_51=true;
}
}
msos.common.xml_innerhtml(key,_4d);
if(_51){
_33(key,false,vkb._vars.ibc,vkb._vars.ibc,vkb._vars.bg,"normal");
}else{
_33(key,true,vkb._vars.fc,vkb._vars.bc,vkb._vars.bg,"bold");
}
}else{
msos.common.xml_innerhtml(key,"&#160;");
_33(key,false,vkb._vars.ibc,vkb._vars.ibc,vkb._vars.bg);
}
}
}
for(var k in vkb._vars.ctrl_keys){
var key=vkb._vars.ctrl_keys[k];
switch(key){
case _41:
case _42:
case _43:
case _44:
break;
case _45:
if(vkb._vars.not_avail[1]){
msos.common.xml_innerhtml(_45,vkb._vars.not_avail[0]);
}else{
_45.innerHTML="Space";
}
_33(key,true,vkb._vars.fc,vkb._vars.bc,"");
break;
case _46:
if(vkb._vars.not_avail[1]){
_33(key,false,vkb._vars.ibc,vkb._vars.ibc,vkb._vars.bg);
}else{
_33(key,true,vkb._vars.fc,vkb._vars.bc,vkb._vars.lsc);
}
break;
default:
if(vkb._vars.not_avail[1]){
_33(key,false,vkb._vars.ibc,vkb._vars.ibc,"");
}else{
_33(key,true,vkb._vars.fc,vkb._vars.bc,"");
}
}
}
_46.innerHTML=msos.characters.available[vkb.i18n_idx][0];
_46.title=msos.characters.available[vkb.i18n_idx][1];
};

